#include "operators.h"
#include "symboltable.h"
#include "codegenerator.h"

using namespace Thinder;

Thinder::Operator::Operator()
{

}

Thinder::Operator::Operator(string op, unsigned int prec, Assoc assoc)
{
    this->op = op;
    this->precedence = prec;
    this->associativity = assoc;
}

OperatorMap processOperators(ParseTree::Thinder &thinder, SymbolTable &s)
{
    OperatorMap operatorMap;
    
    // Add default (built-in) operators
    operatorMap["*"] = Operator("*", 5, Operator::Left);
    operatorMap["/"] = Operator("/", 5, Operator::Left);
    operatorMap["+"] = Operator("+", 6, Operator::Left);
    operatorMap["-"] = Operator("-", 6, Operator::Left);
    
    return operatorMap;
}

void createOperator(string oper, ParseTree::Type type, ParseTree::Type lhs, ParseTree::Type rhs, string internal)
{
    Symbol op;
    op.symbolType = Symbol::Operator;
    op.argumentTypes.push_back(lhs);
    op.argumentTypes.push_back(rhs);
    op.internal = internal;
    op.type = type;
    symbolTable[toName(oper)] = op;
}

void createOperators()
{
    createOperator("+", nameToType(toName("int")), nameToType(toName("int")), nameToType(toName("int")), "t_int_op_plus_int_int");
    createOperator("-", nameToType(toName("int")), nameToType(toName("int")), nameToType(toName("int")), "t_int_op_minus_int_int");
    createOperator("/", nameToType(toName("int")), nameToType(toName("int")), nameToType(toName("int")), "t_int_op_divid_int_int");
    createOperator("*", nameToType(toName("int")), nameToType(toName("int")), nameToType(toName("int")), "t_int_op_multi_int_int");
    
}
